<?php

/**
 * 模型对应数据库表 "orders_paypal".
 *
 * 以下是可用表orders_paypal的栏位:
 * @property string $id
 * @property string $order_number
 * @property string $business
 * @property string $receiver_email
 * @property string $receiver_id
 * @property string $verify_sign
 * @property string $payer_id
 * @property string $txn_id
 * @property string $payment_status
 * @property string $payer_email
 * @property string $payment_amount
 * @property string $payment_currency
 * @property string $payment_fee
 * @property string $payment_date
 * @property string $memo
 * @property string $address_country
 * @property string $address_city
 * @property string $address_street
 * @property string $address_zip
 * @property string $contact_phone
 * @property string $address_status
 * @property string $first_name
 * @property string $last_name
 * @property string $payer_status
 * @property string $pay_type
 */
class OrdersPaypal extends CActiveRecord {

    /**
     * 返回指定的基于“ar”的静态模型类.
     * @return OrdersPaypal the static model class
     * @author nirsh
     * @example
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * 返回数据库表的名.
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function tableName() {
        return 'orders_paypal';
    }

    /**
     * 返回验证规则
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function rules() {
        return array(
            array('order_number, payer_status, pay_type', 'length', 'max' => 20),
            array('business, receiver_email, receiver_id, verify_sign, payer_id, txn_id, payment_status, payment_date, memo, address_country, address_city, address_street, address_status', 'length', 'max' => 255),
            array('payer_email, contact_phone, first_name, last_name', 'length', 'max' => 50),
            array('payment_amount, payment_fee, address_zip', 'length', 'max' => 10),
            array('payment_currency', 'length', 'max' => 3),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, order_number, business, receiver_email, receiver_id, verify_sign, payer_id, txn_id, payment_status, payer_email, payment_amount, payment_currency, payment_fee, payment_date, memo, address_country, address_city, address_street, address_zip, contact_phone, address_status, first_name, last_name, payer_status, pay_type', 'safe', 'on' => 'search'),
        );
    }

    /**
     * 返回关联规则数组。
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * 通过ID获取名称
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function getNameById($id, $nameField) {
        $res = $this->findByPk($id);
        return $res[$nameField] ? $res[$nameField] : '';
    }

    /**
     * 返回属性标签(名称= >标签)数组
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'order_number' => 'Order Number',
            'business' => 'Business',
            'receiver_email' => 'Receiver Email',
            'receiver_id' => 'Receiver',
            'verify_sign' => 'Verify Sign',
            'payer_id' => 'Payer',
            'txn_id' => 'Txn',
            'payment_status' => 'Payment Status',
            'payer_email' => 'Payer Email',
            'payment_amount' => 'Payment Amount',
            'payment_currency' => 'Payment Currency',
            'payment_fee' => 'Payment Fee',
            'payment_date' => 'Payment Date',
            'memo' => 'Memo',
            'address_country' => 'Address Country',
            'address_city' => 'Address City',
            'address_street' => 'Address Street',
            'address_zip' => 'Address Zip',
            'contact_phone' => 'Contact Phone',
            'address_status' => 'Address Status',
            'first_name' => 'First Name',
            'last_name' => 'Last Name',
            'payer_status' => 'Payer Status',
            'pay_type' => 'Pay Type',
        );
    }

    /**
     * 设置查询相关条件
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('order_number', $this->order_number, true);
        $criteria->compare('business', $this->business, true);
        $criteria->compare('receiver_email', $this->receiver_email, true);
        $criteria->compare('receiver_id', $this->receiver_id, true);
        $criteria->compare('verify_sign', $this->verify_sign, true);
        $criteria->compare('payer_id', $this->payer_id, true);
        $criteria->compare('txn_id', $this->txn_id, true);
        $criteria->compare('payment_status', $this->payment_status, true);
        $criteria->compare('payer_email', $this->payer_email, true);
        $criteria->compare('payment_amount', $this->payment_amount, true);
        $criteria->compare('payment_currency', $this->payment_currency, true);
        $criteria->compare('payment_fee', $this->payment_fee, true);
        $criteria->compare('payment_date', $this->payment_date, true);
        $criteria->compare('memo', $this->memo, true);
        $criteria->compare('address_country', $this->address_country, true);
        $criteria->compare('address_city', $this->address_city, true);
        $criteria->compare('address_street', $this->address_street, true);
        $criteria->compare('address_zip', $this->address_zip, true);
        $criteria->compare('contact_phone', $this->contact_phone, true);
        $criteria->compare('address_status', $this->address_status, true);
        $criteria->compare('first_name', $this->first_name, true);
        $criteria->compare('last_name', $this->last_name, true);
        $criteria->compare('payer_status', $this->payer_status, true);
        $criteria->compare('pay_type', $this->pay_type, true);

        return new CActiveDataProvider(get_class($this), array(
                    'criteria' => $criteria,
                ));
    }

}